﻿using AutoMapper;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using VM.Common.Result;
using VM.Entity.EntityDto.Topic;
using VM.Entity.EntityMap.Condition;
using VM.Entity.EntityMap.Files;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Title;
using VM.Entity.EntityMap.Topic;
using VM.Entity.EntityMap.User;
using VM.IDAL.Topic;

namespace VM.DAL.topic
{
    public class TopicDAL : BaseDAL, ITopicDAL
    {
        protected ISqlSugarClient _Client { get; set; }
        private readonly IMapper _IMapper;
        public TopicDAL(ISqlSugarClient client, IMapper iMapper) : base(client)
        {
            _Client = client;
            _IMapper = iMapper;
        }



        public bool insertTopicType(sys_topicType obj)
        {

            int Res = _Client.Insertable(obj)
                      .ExecuteCommand();
            if (Res > 0)
            {

                return true;
            }
            else
            {
                return false;

            }

        }



        public PagingData<getTopicTypeListDto> getTopicTypeListConditon<T>(List<Condition> whereObj, int pageSize, int pageIndex, Expression<Func<T, object>> funcOrderby, bool isAsc = true) where T : class
        {
            var listRes = _Client.Queryable<sys_topicType>()
                          .Includes(a => a.createUser)
                          .Includes(a => a.updateUser);


            PagingData<sys_topicType> result = new PagingData<sys_topicType>()
            {
                dataList = listRes.ToPageList(pageIndex, pageSize),
                pageIndex = pageIndex,
                pageSize = pageSize,
                recordCount = listRes.Count(),
            };

            PagingData<getTopicTypeListDto> resend = _IMapper.Map<PagingData<sys_topicType>, PagingData<getTopicTypeListDto>>(result);
            return resend;
        }

        public bool InsertTopic(sys_topic obj)
        {

            bool Res = _Client.InsertNav(obj)
                .Include(a => a.files)
                .ExecuteCommand();


            return Res;
        }


    }
}
